import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import { resolve } from "path";
// https://vite.dev/config/
export default defineConfig({
  plugins: [
    react(),
    // dts 插件已禁用，使用手动生成的类型文件
  ],
  resolve: {
    // 确保 Vite 能解析 .tsx 文件
    extensions: [".tsx", ".ts", ".js", ".jsx"],
  },
  build: {
    outDir: "dist",
    lib: {
      entry: resolve("./src/index.ts"), // 组件库入口
      name: "ReactDentify", // UMD 全局变量名
      fileName: (format) => `index.${format}.js`,
      formats: ["es", "cjs", "umd"],
    },
    rollupOptions: {
      // 外部化依赖，避免打包进库
      external: ["react", "react-dom", "react/jsx-runtime"],
      output: {
        globals: {
          react: "React",
          "react-dom": "ReactDOM",
          "react/jsx-runtime": "jsxRuntime",
        },
        preserveModules: false,
      },
    },
    cssCodeSplit: true,
    sourcemap: true,
    minify: "esbuild",
  },
});
